﻿; 暗黑3安装目录
d3_dir = E:\Game\暗黑破坏神III
; 暗黑3窗口标题
d3_win_title = ahk_class D3 Main Window Class
;////////////////////////////////////////////////////////////////
; 密码
pwd = file@twd3
; 密码框坐标
pwd_x = 773
pwd_y = 570d3
;////////////////////////////////////////////////////////////////
; 退出游戏按键坐标
exit_game_x = 214
exit_game_y = 461
;////////////////////////////////////////////////////////////////
; 鼠标左键原地攻击标志
stand_attack_flag = 1
;////////////////////////////////////////////////////////////////
buff3_flag = 0
buff3_tick = 0
buff4_flag = 0
buff4_tick = 0
buff_interval = 1000
buff_class = 0
; 武僧
WS = 1
; 野蛮人
BB = 2
; 法师
FS = 3
;////////////////////////////////////////////////////////////////
ice_flag = 0
;////////////////////////////////////////////////////////////////
#SingleInstance
CoordMode, ToolTip | Mouse
SetKeyDelay, 25, 25
Hotkey, ~e, StandAttack, on
HotKey, ~q, IceAttack, on
return
;////////////////////////////////////////////////////////////////
ShowToolTip(msg, interval = 750)
{
	ToolTip, %msg%
	SetTimer, RemoveToolTip, %interval%
}

RemoveToolTip:
	SetTimer, RemoveToolTip, off
	ToolTip
return
;////////////////////////////////////////////////////////////////
;按d+3启动暗黑3
~d & ~3::
	IfWinNotExist, %d3_win_title%
	{
		Run, Diablo III Launcher.exe, %d3_dir%
	}
	else
	{
		WinActivate, %d3_win_title%
	}
return
;////////////////////////////////////////////////////////////////
;一键退出游戏
~F1::
	IfWinActive, %d3_win_title%
	{
		ControlSend, , {Esc}, %d3_win_title%
		MouseMove, %exit_x%, %exit_y%
		ControlClick, , %d3_win_title%

		disable_buff3(buff3_flag, buff3_tick, 0)
		disable_buff4(buff4_flag, buff4_tick, 0)
		ShowToolTip("disable 3,4")
	}
return

;////////////////////////////////////////////////////////////////
;登录界面输入密码并按登录键
;~F2::
;	IfWinActive, %d3_win_title%
;	{
;		ControlSend, , {Enter}, %d3_win_title%
;		MouseMove %pwd_x%,%pwd_y%
;		ControlClick, , %d3_win_title%
;		Clipboard = %pwd%
;		ControlSend, , ^v{Enter}, %d3_win_title%
;		ClipWait
;		Clipboard = 
;	}
;return
;///////////////////////////////////////////////////////////////
; 设定职业
~F3::
	IfWinActive, %d3_win_title%
	{
		if buff_class = 0
		{
			buff_class = WS
			ShowToolTip("WS mode")
		}
		else if buff_class = WS
		{
			buff_class = BB
			ShowToolTip("BB mode")
		}
		else if buff_class = BB
		{
			buff_class = FS
			ShowToolTip("FS mode")
		}
		else if buff_class = FS
		{
			buff_class = 0
			ShowToolTip("off")
		}
	}
return
;///////////////////////////////////////////////////////////////
; 退出本工具
~F4::
	ExitApp
return
;///////////////////////////////////////////////////////////////
enable_buff3(ByRef flag, ByRef tick, ShowMsg = 1)
{
	flag := 1
	tick := 0

	SetTimer, buff3, %buff_interval%
	
	if ShowMsg = 1
	{
		ShowToolTip("enable 3")
	}
}

disable_buff3(ByRef flag, ByRef tick, ShowMsg = 1)
{
	flag := 0
	tick := 0

	SetTimer, buff3, off

	if ShowMsg = 1
	{
		ShowToolTip("disable 3")
	}
}

enable_buff4(ByRef flag, ByRef tick, ShowMsg = 1)
{
	flag := 1
	tick := 0
	
	SetTimer, buff4, %buff_interval%
	
	if ShowMsg = 1
	{
		ShowToolTip("enable 4")
	}
}

disable_buff4(ByRef flag, ByRef tick, ShowMsg = 1)
{
	flag := 0
	tick := 0

	SetTimer, buff4, off

	if ShowMsg = 1
	{
		ShowToolTip("disable 4")
	}
}
;///////////////////////////////////////////////////////////////
~3::
	IfWinActive, %d3_win_title%
	{
		if buff3_flag = 0
		{
			if buff_class = WS
			{
				enable_buff3(buff3_flag, buff3_tick)
			}
			else if buff_class = BB
			{
				enable_buff3(buff3_flag, buff3_tick)
			}
			else if buff_class = FS
			{
				enable_buff3(buff3_flag, buff3_tick)
			}
			
			ControlSend, , {3}, %d3_win_title%
		}
		else
		{
			if buff_class = WS
			{
				disable_buff3(buff3_flag, buff3_tick)
			}
			else if	buff_class = BB
			{
				disable_buff3(buff3_flag, buff3_tick)
			}
			else if buff_class = FS
			{
				disable_buff3(buff3_flag, buff3_tick)
			}
		}		
	}
return

~4::
	IfWinActive, %d3_win_title%
	{
		if buff4_flag = 0
		{
			if buff_class = WS
			{
				enable_buff4(buff4_flag, buff4_tick)
			}
			else if buff_class = BB
			{
				enable_buff4(buff4_flag, buff4_tick)
			}
			else if buff_class = FS
			{
				enable_buff4(buff4_flag, buff4_tick)
			}
			
			ControlSend, , {4}, %d3_win_title%
		}
		else
		{
			if buff_class = WS
			{
				disable_buff4(buff4_flag, buff4_tick)
			}
			else if	buff_class = BB
			{
				disable_buff4(buff4_flag, buff4_tick)
			}
			else if buff_class = FS
			{
				disable_buff4(buff4_flag, buff4_tick)
			}
		}
	}
return
;///////////////////////////////////////////////////////////////
; 定时刷buff3
buff3:
	IfWinActive, %d3_win_title%
	{
		if buff_class = WS
		{
			buff3_ws(buff3_tick)
		}
		else if buff_class = BB
		{
			buff3_bb(buff3_tick)
		}
		else if buff_class = FS
		{
			buff3_fs(buff3_tick)
		}
		else if buff_class = 0
		{
			return
		}
		
		buff3_tick++
		SetTimer, buff3, %buff_interval%
	}
return

; 定时刷buff4
buff4:
	IfWinActive, %d3_win_title%
	{
		if buff_class = WS
		{
			buff4_ws(buff4_tick)
		}
		else if buff_class = BB
		{
			buff4_bb(buff4_tick)
		}
		else if buff_class = FS
		{
			buff4_fs(buff4_tick)
		}
		else if buff_class = 0
		{
			return
		}
		
		buff4_tick++
		SetTimer, buff4, %buff_interval%
	}
return

active_buff(tick, interval, key)
{
	if tick > 0
	{
		i := Mod(tick, interval)
		if i = 0
		{
			ControlSend, , {%key%}, %d3_win_title%
		}
	}
}

active_feng(tick)
{
	active_buff(tick, 4, 3)
}

active_zhenyan(tick)
{
	active_buff(tick, 170, 4)
}

buff3_ws(tick)
{
	active_feng(tick)
}

buff4_ws(tick)
{
	active_zhenyan(tick)
}

active_fang(tick)
{
	active_buff(tick, 50, 4)
}

active_gong(tick)
{
	active_buff(tick, 110, 3)
}

buff3_bb(tick)
{
	active_fang(tick)
}

buff4_bb(tick)
{
	active_gong(tick)
}

active_jia(tick)
{
	active_buff(tick, 540, 4)
}

buff3_fs(tick)
{
	active_buff(tick, 540, 3)
}

buff4_fs(tick)
{
	active_jia(tick)
}
;///////////////////////////////////////////////////////////////
~WheelDown::
	IfWinActive, %d3_win_title%
	{
		if buff_class = WS
		{
			if buff3_flag = 1
			{
				disable_buff3(buff3_flag, buff3_tick)
			}
		}
	}
return

~r::
	IfWinActive, %d3_win_title%
	{
		if buff_class = WS
		{
			if buff3_flag = 1
			{
				disable_buff3(buff3_flag, buff3_tick)
			}
		}
	}
return
;///////////////////////////////////////////////////////////////
;鼠标左键原地攻击
StandAttack:
	IfWinActive, %d3_win_title%
	{
		if stand_attack_flag = 1
		{
			MouseGetPos, mouse_x, mouse_y
			ControlSend, , {Shift Down}, %d3_win_title%
			ControlClick, X%mouse_x% Y%mouse_y%, %d3_win_title%
			ControlSend, , {Shift Up}, %d3_win_title%
		}
	}
return
;///////////////////////////////////////////////////////////////
;鼠标左键原地攻击开关
!e::
	IfWinActive, %d3_win_title%
	{
		if stand_attack_flag = 0
		{
			stand_attack_flag = 1
			Hotkey, ~e, StandAttack, on
			ShowToolTip("enable e")
		}
		else
		{
			stand_attack_flag = 0
			Hotkey, ~e, StandAttack, off
			ShowToolTip("disable e")
		}
	}
return
;///////////////////////////////////////////////////////////////
; 冰法宏, 连按2,3,1
IceAttack:
	IfWinActive, %d3_win_title%
	{
		if ice_flag = 1
		{
			MouseGetPos, mouse_x, mouse_y
			ControlSend, , {Space Down}, %d3_win_title%
			ControlClick, X%mouse_x% Y%mouse_y%, %d3_win_title%
			ControlSend, , {2}{3}{1}, %d3_win_title%
			ControlSend, , {Space Up}, %d3_win_title%
		}
	}
return
;///////////////////////////////////////////////////////////////
; 冰法宏开关
!q::
	IfWinActive, %d3_win_title%
	{
		if ice_flag = 0
		{
			ice_flag = 1
			Hotkey, ~q, IceAttack, on
			ShowToolTip("enable q")
		}
		else
		{
			ice_flag = 0
			Hotkey, ~q, IceAttack, off
			ShowToolTip("disable q")
		}
	}
return
;///////////////////////////////////////////////////////////////
;显示鼠标当前坐标
!m::
	IfWinActive, %d3_win_title%
	{
		mouse_x = 0
		mouse_y = 0
		MouseGetPos, mouse_x, mouse_y
		msg = x = %mouse_x%, y = %mouse_y%
		ShowToolTip(msg)
	}
return
;///////////////////////////////////////////////////////////////
